package com.red.wood.module.eval.web;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.google.inject.internal.Lists;
import com.google.inject.internal.Maps;
import com.red.wood.common.util.CommonUtils;
import com.red.wood.common.util.IMap;
import com.red.wood.module.eval.model.ApplicationCdn;
import com.red.wood.module.eval.model.ApplicationCoverInfo;
import com.red.wood.module.eval.model.ApplicationInstallAddrBack;
import com.red.wood.module.eval.model.ApplicationInstallAddrGame;
import com.red.wood.module.eval.model.EvalApplicationCdnCname;
import com.red.wood.module.eval.model.EvalApplicationCdnNode;
import com.red.wood.module.eval.model.SingleTask;
import com.red.wood.module.eval.model.TaskAudit;
import com.red.wood.module.eval.service.ApplicationCdnCNameService;
import com.red.wood.module.eval.service.ApplicationCdnNodeService;
import com.red.wood.module.eval.service.ApplicationCdnService;
import com.red.wood.module.eval.service.ApplicationCoverInfoService;
import com.red.wood.module.eval.service.ApplicationFileService;
import com.red.wood.module.eval.service.ApplicationInstallAddrBackService;
import com.red.wood.module.eval.service.ApplicationInstallAddrGameService;
import com.red.wood.module.eval.service.DictionaryService;
import com.red.wood.module.eval.service.EvalProjectService;
import com.red.wood.module.eval.service.SingleTaskService;
import com.red.wood.module.eval.service.TaskAuditService;
import com.red.wood.module.eval.service.TaskFlowService;
import com.red.wood.module.eval.until.CommonUtil;
import com.red.wood.module.system.service.SwUserService;

@Controller
@RequestMapping("/evalApplication")
public class EvalApplicationController {

	private static final Log log = LogFactory.getLog(EvalApplicationController.class);
	
	// 上传文件地址根目录
	private static final String ROOTPATH = "EVAL_UPLOADFILE_ROOTPATH" ;
	// 上传文件地址子目录
	private static final String CHILDPATH = "EVAL_UPLOADFILE_CHILDPATH";
	// 编号前缀
	private static final String NUMBER_PREFIX = "AQ";
	// 编号后缀
	private static final String NUMBER_SUFFIX = "0001";
	// 评测通过联系人及联系方式
	private static final String EVAL_REPORT_USER = "EVAL_REPORT_USER";
	private static final String EVAL_REPORT_CONTACT = "EVAL_REPORT_CONTACT";
	
	@Autowired
	private ApplicationCdnService applicationCdnService;
	@Autowired
	private SingleTaskService singleTaskService;
	@Autowired
	private TaskFlowService taskFlowService;
	@Autowired
	private TaskAuditService taskAuditService;
	@Autowired
	private ApplicationCdnNodeService applicationCdnNodeService;
	@Autowired
	private ApplicationCdnCNameService applicationCdnCNameService;
	@Autowired
	private DictionaryService dictionaryService;
	@Autowired
	private ApplicationCoverInfoService applicationCoverInfoService;
	@Autowired
	private ApplicationInstallAddrBackService applicationInstallAddrBackService;
	@Autowired
	private ApplicationInstallAddrGameService applicationInstallAddrGameService;
	@Autowired
	private ApplicationFileService applicationFileService;
	@Autowired
	private SwUserService swUserService;
	@Autowired
	private EvalProjectService evalProjectService;
	
	/**
	 * 工单审核 & 评测
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping
	public ModelAndView index(HttpServletRequest request, HttpServletResponse response){
		String htmlView = "applicationIdcNotInterAudit"; //idc(不含互联网资源协作)
		String statue = request.getParameter("statue");
		String type = request.getParameter("type");
		String backViewType = CommonUtils.valueOf(request.getParameter("backViewType")); // 返回界面标识 1-企业侧 2-管局侧
		String showType = CommonUtils.valueOf(request.getParameter("showType"));
		
		if(StringUtils.isNotBlank(backViewType) && Integer.valueOf(backViewType) == 1){
			if(StringUtils.equals(showType, "view")) {
				if(StringUtils.isNotBlank(type)){
					if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_ONLYINTER){ // idc业务评测(仅限互联网资源协作)
						htmlView = "applicationIdcOnlyInterAudit";
					} else if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_ISP) { // ISP业务评测 
						htmlView = "applicationIspAudit";
					} else if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_CDN) { // CDN业务评测
						htmlView = "applicationCdnAudit";
					} else { //idc(不含互联网资源协作)
						htmlView = "applicationIdcNotInterAudit";
					}
				}
			}else {
				// 评测通过
				if(StringUtils.isNotBlank(statue) && (Integer.valueOf(statue) == SingleTask.EVAL_SINGLETASK_STATUE_ADOPT)){ 
					if(StringUtils.isNotBlank(type)){
						if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_ONLYINTER){ // idc业务评测(仅限互联网资源协作)
							htmlView = "evalAdoptIdcOnlyInter";
						} else if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_ISP) { // ISP业务评测 
							htmlView = "evalAdoptIsp";
						} else if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_CDN) { // CDN业务评测
							htmlView = "evalAdoptCdn";
						} else {
							htmlView = "evalAdoptIdcNotInter";
						}
					}
				} else if(StringUtils.isNotBlank(statue) && (Integer.valueOf(statue) == SingleTask.EVAL_SINGLETASK_STATUE_NOTADOPT)){ 
					// 评测不通过
					if(StringUtils.isNotBlank(type)){
						if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_ONLYINTER){ // idc业务评测(仅限互联网资源协作)
							htmlView = "evalNotAdoptIdcOnlyInter";
						} else if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_ISP) { // ISP业务评测 
							htmlView = "evalNotAdoptIsp";
						} else if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_CDN) { // CDN业务评测
							htmlView = "evalNotAdoptCdn";
						} else {
							htmlView = "evalNotAdoptIdcNotInter";
						}
					}
				} else {
					if(StringUtils.isNotBlank(type)){
						if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_ONLYINTER){ // idc业务评测(仅限互联网资源协作)
							htmlView = "applicationIdcOnlyInterAudit";
						} else if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_ISP) { // ISP业务评测 
							htmlView = "applicationIspAudit";
						} else if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_CDN) { // CDN业务评测
							htmlView = "applicationCdnAudit";
						} else { //idc(不含互联网资源协作)
							htmlView = "applicationIdcNotInterAudit";
						}
					}
				}
			}
		} else if(StringUtils.isNotBlank(backViewType) && Integer.valueOf(backViewType) == 2){
			if(StringUtils.equals(showType, "view")) {
				if(StringUtils.isNotBlank(type)){
					if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_ONLYINTER){ // idc业务评测(仅限互联网资源协作)
						htmlView = "applicationIdcOnlyInterAudit";
					} else if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_ISP) { // ISP业务评测 
						htmlView = "applicationIspAudit";
					} else if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_CDN) { // CDN业务评测
						htmlView = "applicationCdnAudit";
					} else {
						htmlView = "applicationIdcNotInterAudit";
					}
				}
			}else {
				// 评测通过
				if(StringUtils.isNotBlank(statue) && (Integer.valueOf(statue) == TaskAudit.EVAL_TASTAUDIT_STATUE_ADOPT)){
					if(StringUtils.isNotBlank(type)){
						if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_ONLYINTER){ // idc业务评测(仅限互联网资源协作)
							htmlView = "evalAdoptIdcOnlyInter";
						} else if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_ISP) { // ISP业务评测 
							htmlView = "evalAdoptIsp";
						} else if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_CDN) { // CDN业务评测
							htmlView = "evalAdoptCdn";
						} else {
							htmlView = "evalAdoptIdcNotInter";
						}
					}
				} else if(StringUtils.isNotBlank(statue) && (Integer.valueOf(statue) == TaskAudit.EVAL_TASTAUDIT_STATUE_NOTADOPT)){
					// 评测不通过
					if(StringUtils.isNotBlank(type)){
						if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_ONLYINTER){ // idc业务评测(仅限互联网资源协作)
							htmlView = "evalNotAdoptIdcOnlyInter";
						} else if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_ISP) { // ISP业务评测 
							htmlView = "evalNotAdoptIsp";
						} else if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_CDN) { // CDN业务评测
							htmlView = "evalNotAdoptCdn";
						} else {
							htmlView = "evalNotAdoptIdcNotInter";
						}
					}
				} else {
					if(StringUtils.isNotBlank(type)){
						if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_ONLYINTER){ // idc业务评测(仅限互联网资源协作)
							htmlView = "applicationIdcOnlyInterAudit";
						} else if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_ISP) { // ISP业务评测 
							htmlView = "applicationIspAudit";
						} else if(Integer.valueOf(type) ==  SingleTask.EVAL_SINGLETASK_TYPE_CDN) { // CDN业务评测
							htmlView = "applicationCdnAudit";
						} else {
							htmlView = "applicationIdcNotInterAudit";
						}
					}
				}
			}
		}
		
		ModelAndView mv = new ModelAndView(htmlView);
		String singleTaskId = CommonUtils.valueOf(request.getParameter("singleTaskId"));
		mv.addObject("singleTaskId", singleTaskId); 
		mv.addObject("statue", statue); 
		mv.addObject("backViewType", backViewType); 
		mv.addObject("userId", CommonUtils.valueOf(request.getParameter("userId")));
		mv.addObject("type", type);
		mv.addObject("form_number",CommonUtils.valueOf(request.getParameter("form_number")));
		return mv;
	}
	
	/**
	 * 获取审核信息
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "getCdnAudit", method = RequestMethod.POST)
	@ResponseBody
	public String getCdnAudit(HttpServletRequest request, HttpServletResponse response){
		JSONObject json = new JSONObject();
		try{
			String singleTaskId = CommonUtils.valueOf(request.getParameter("singleTaskId"));
			String backViewType = CommonUtils.valueOf(request.getParameter("backViewType"));
			String statue = CommonUtils.valueOf(request.getParameter("statue"));
			
			Map<String,Object> param = new HashMap<String,Object>();
			param.put("singleTaskId", singleTaskId); //评测任务id
			
			Map<String,Object> data = applicationCdnService.getEntity(param);
			if(data == null){
				data = Maps.newHashMap();
				
				// 获取表单编号, 新增时
				/*Map<String, Object> map = applicationCdnService.getLastData();
				if(map != null){
					String num = map.get("number").toString();
					String newNum = num.replace(NUMBER_PREFIX, "");
					newNum = NUMBER_PREFIX + (Long.valueOf(newNum).longValue() + 1);
					data.put("number", newNum);
				} else {
					Calendar now = Calendar.getInstance();
					String number = NUMBER_PREFIX + now.get(Calendar.YEAR) + NUMBER_SUFFIX;
					data.put("number", number);
				}*/
				data.put("number",CommonUtils.valueOf(request.getParameter("form_number")));
				// 获取当前系统时间, 新增时
				SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
				data.put("applicationDate", df.format(new Date()));
			} else {
				// 获取表单编号，修改时 //TODO
				/*Map<String, Object> map = applicationCdnService.getLastData();
				if(map != null){
					String number = map.get("number").toString();
					data.put("number", number);
				}*/
				/*data.put("number",CommonUtils.valueOf(request.getParameter("form_number")));*/
				
				if((StringUtils.isNotBlank(backViewType) && Integer.valueOf(backViewType).intValue() == 1) 
						&& (StringUtils.isNotBlank(statue) && Integer.valueOf(statue).intValue() == SingleTask.EVAL_SINGLETASK_STATUE_NOTSUB)){
					// 获取当前系统时间, 新增时
					SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
					data.put("applicationDate", df.format(new Date()));
				}
			}
			// 获取 业务类型
			Map<String, Object> singleTaskMap = singleTaskService.getById(singleTaskId);
			if(singleTaskMap != null){
				data.put("type", singleTaskMap.get("name"));
			}
			
			// 根据userId 调用 sqlServer 获取用户信息
			String userId = CommonUtils.valueOf(request.getParameter("userId"));
			System.out.println("userId 值为..."+ userId);
			if(StringUtils.isNotBlank(userId)){
				try{
					Map<String, Object> map = swUserService.getById(userId);
					if(map != null){
						System.out.println("获得返回的user对象值为..."+ map.toString());
						//System.out.println("获得返回的user对象值为..."+ map.get("RealName")+"");
						setDataByMay(data, map);
					}
				} catch (Exception e){
					if(log.isErrorEnabled()){
						log.error(e.getMessage(),e);
					}
				}
			}
			
			// 获取评测通过信息，责任人和联系方式，及处理时间
			String deptPerson = dictionaryService.getValueByTypeAndKey(EVAL_REPORT_USER, "0");
			if(StringUtils.isBlank(deptPerson)){
				log.error("请检查字典表EVAL_REPORT_USER配置");
			} else {
				data.put("deptPerson", deptPerson);
			}
			String personTel = dictionaryService.getValueByTypeAndKey(EVAL_REPORT_CONTACT, "0");
			if(StringUtils.isBlank(deptPerson)){
				log.error("请检查字典表EVAL_REPORT_CONTACT配置");
			} else {
				data.put("personTel", personTel);
			}
			Map<String, Object> taskAuditMap = taskAuditService.getBySingleTaskId(singleTaskId);
			if(null != taskAuditMap && StringUtils.isNotBlank(taskAuditMap.get("updateTime").toString())){
				Date handleTime = (Date)taskAuditMap.get("updateTime");
				Calendar cal = Calendar.getInstance(); 
				cal.setTime(handleTime);
				data.put("handleDay", cal.get(Calendar.DAY_OF_MONTH));
				data.put("handleMonth", (cal.get(Calendar.MONTH) + 1)+"");
				data.put("handleYear", cal.get(Calendar.YEAR));
			}
			
			json.put("flag", true);
			json.put("data", data);
			json.put("cnameData", applicationCdnCNameService.getBySingleTaskId(singleTaskId));
			json.put("nodeData", applicationCdnNodeService.getBySingleTaskId(singleTaskId));
			json.put("coverData", applicationCoverInfoService.getBySingleTaskId(singleTaskId));
			json.put("gameData", applicationInstallAddrGameService.getBySingleTaskId(singleTaskId));
			json.put("backData", applicationInstallAddrBackService.getBySingleTaskId(singleTaskId));
			json.put("fileData", applicationFileService.getBySingleTaskId(singleTaskId));
		}catch(Exception e){
			if(log.isErrorEnabled()){
				log.error(e.getMessage(),e);
			}
			json.put("flag",false);
		}
		return json.toString();
	}
	
	private void setDataByMay(Map<String,Object> data, Map<String, Object> map){
		if(StringUtils.isNotBlank(CommonUtils.valueOf(map.get("Company")))){
			data.put("name", map.get("Company"));
		}
		if(StringUtils.isNotBlank(CommonUtils.valueOf(map.get("Email")))){
			data.put("eMail", map.get("Email"));
		}
		if(StringUtils.isNotBlank(CommonUtils.valueOf(map.get("Address")))){
			data.put("address", map.get("Address"));
		}
		if(StringUtils.isNotBlank(CommonUtils.valueOf(map.get("Mobile")))){
			data.put("moveTle", map.get("Mobile"));
		}
		if(StringUtils.isNotBlank(CommonUtils.valueOf(map.get("Contact")))){
			data.put("contacts", map.get("Contact"));
		}
	}
	
	private void addNodeList(List<EvalApplicationCdnNode> list, String singleTaskId){
		List<Map<String, Object>> paramList = Lists.newArrayList();
		if(list != null){
			for(EvalApplicationCdnNode entity: list){
				if(null != entity && StringUtils.isNotBlank(entity.getProvince())){
					Map<String, Object> map = new HashMap<>();
					map.put("singleTaskId", singleTaskId);
					map.put("province", entity.getProvince());
					map.put("city", entity.getCity());
					map.put("name", entity.getName());
					map.put("address", entity.getAddress());
					paramList.add(map);
				}
			}
			applicationCdnNodeService.add(paramList);
		}
	}
	
	private void addCnameList(List<EvalApplicationCdnCname> list, String singleTaskId){
		List<Map<String, Object>> paramList = Lists.newArrayList();
		if(list != null){
			for(EvalApplicationCdnCname entity: list){
				if(null != entity && StringUtils.isNotBlank(entity.getDomain())){
					Map<String, Object> map = new HashMap<>();
					map.put("singleTaskId", singleTaskId);
					map.put("domain", entity.getDomain());
					map.put("icp", entity.getIcp());
					paramList.add(map);
				}
			}
			applicationCdnCNameService.add(paramList);
		}
	}
	
	private void addCoverList(List<ApplicationCoverInfo> list, String singleTaskId){
		List<Map<String, Object>> paramList = Lists.newArrayList();
		if(list != null){
			for(ApplicationCoverInfo entity: list){
				if(null != entity && StringUtils.isNotBlank(entity.getCoverName())){
					Map<String, Object> map = new HashMap<>();
					map.put("singleTaskId", singleTaskId);
					map.put("coverName", entity.getCoverName());
					map.put("gbps", entity.getGbps());
					map.put("coverMode", entity.getCoverMode());
					paramList.add(map);
				}
			}
			applicationCoverInfoService.add(paramList);
		}
	}
	
	private void addGameInstallList(List<ApplicationInstallAddrGame> list, String singleTaskId){
		List<Map<String, Object>> paramList = Lists.newArrayList();
		if(list != null){
			for(ApplicationInstallAddrGame entity: list){
				if(null != entity && StringUtils.isNotBlank(entity.getName())){
					Map<String, Object> map = new HashMap<>();
					map.put("singleTaskId", singleTaskId);
					map.put("name", entity.getName());
					map.put("model", entity.getModel());
					map.put("floor", entity.getFloor());
					map.put("frameName", entity.getFrameName());
					map.put("seat", entity.getSeat());
					paramList.add(map);
				}
			}
			applicationInstallAddrGameService.add(paramList);
		}
	}
	
	private void addBackInstallList(List<ApplicationInstallAddrBack> list, String singleTaskId){
		List<Map<String, Object>> paramList = Lists.newArrayList();
		if(list != null){
			for(ApplicationInstallAddrBack entity: list){
				if(entity != null && StringUtils.isNotBlank(entity.getName())){
					Map<String, Object> map = new HashMap<>();
					map.put("singleTaskId", singleTaskId);
					map.put("name", entity.getName());
					map.put("model", entity.getModel());
					map.put("floor", entity.getFloor());
					map.put("frameName", entity.getFrameName());
					map.put("seat", entity.getSeat());
					paramList.add(map);
				}
			}
			applicationInstallAddrBackService.add(paramList);
		}
	}
	
	private IMap setParamCdn(HttpServletRequest request){
		IMap param = new IMap();
		param.put("singleTaskId", CommonUtils.valueOf(request.getParameter("singleTaskId")));
		param.put("number", CommonUtils.valueOf(request.getParameter("number")));
		param.put("applicationDate", CommonUtils.valueOf(request.getParameter("applicationDate")));
		param.put("name", CommonUtils.valueOf(request.getParameter("name")));
		param.put("address", CommonUtils.valueOf(request.getParameter("address")));
		param.put("code", CommonUtils.valueOf(request.getParameter("code")));
		param.put("contacts", CommonUtils.valueOf(request.getParameter("contacts")));
		param.put("tel", CommonUtils.valueOf(request.getParameter("tel")));
		param.put("moveTle", CommonUtils.valueOf(request.getParameter("moveTle")));
		param.put("fax", CommonUtils.valueOf(request.getParameter("fax")));
		param.put("eMail", CommonUtils.valueOf(request.getParameter("eMail")));
		param.put("type", CommonUtils.valueOf(request.getParameter("type")));
		param.put("gbps", CommonUtils.valueOf(request.getParameter("gbps")));
		param.put("linkNum", CommonUtils.valueOf(request.getParameter("linkNum")));
		param.put("systemName", CommonUtils.valueOf(request.getParameter("systemName")));
		param.put("productionUnit", CommonUtils.valueOf(request.getParameter("productionUnit")));
		param.put("version", CommonUtils.valueOf(request.getParameter("version")));
		param.put("handleInfo", CommonUtils.valueOf(request.getParameter("handleInfo")));
		param.put("remark", CommonUtils.valueOf(request.getParameter("remark")));
		param.put("duties", CommonUtils.valueOf(request.getParameter("duties")));
		param.put("pushTime", CommonUtils.valueOf(request.getParameter("pushTime")));
		
		param.put("houseNum", CommonUtils.valueOf(request.getParameter("houseNum")));
		param.put("houseName", CommonUtils.valueOf(request.getParameter("houseName")));
		param.put("isShare", CommonUtils.valueOf(request.getParameter("isShare")));
		param.put("gameProvince", CommonUtils.valueOf(request.getParameter("gameProvince")));
		param.put("gameCity", CommonUtils.valueOf(request.getParameter("gameCity")));
		param.put("houseAddress", CommonUtils.valueOf(request.getParameter("houseAddress")));
		param.put("postalCode", CommonUtils.valueOf(request.getParameter("postalCode")));
		param.put("idcType", CommonUtils.valueOf(request.getParameter("idcType")));
		param.put("unitFullName", CommonUtils.valueOf(request.getParameter("unitFullName")));
		param.put("contractName", CommonUtils.valueOf(request.getParameter("contractName")));
		param.put("signTime", CommonUtils.valueOf(request.getParameter("signTime")));
		param.put("contractEffBeginTime", CommonUtils.valueOf(request.getParameter("contractEffBeginTime")));
		param.put("contractEffEndTime", CommonUtils.valueOf(request.getParameter("contractEffEndTime")));
		param.put("moduleType1", CommonUtils.valueOf(request.getParameter("moduleType1")));
		param.put("moduleContent1", CommonUtils.valueOf(request.getParameter("moduleContent1")));
		param.put("moduleType2", CommonUtils.valueOf(request.getParameter("moduleType2")));
		param.put("moduleContent2", CommonUtils.valueOf(request.getParameter("moduleContent2")));
		param.put("houseNodeName", CommonUtils.valueOf(request.getParameter("houseNodeName")));
		param.put("nodeNum", CommonUtils.valueOf(request.getParameter("nodeNum")));
		param.put("evalType", CommonUtils.valueOf(request.getParameter("evalType")));
		param.put("lastEvalTime", CommonUtils.valueOf(request.getParameter("lastEvalTime")));
		param.put("lastNum", CommonUtils.valueOf(request.getParameter("lastNum")));
		param.put("lastMechanism", CommonUtils.valueOf(request.getParameter("lastMechanism")));
		param.put("deployInfo", CommonUtils.valueOf(request.getParameter("deployInfo")));
		param.put("deployIsShare", CommonUtils.valueOf(request.getParameter("deployIsShare")));
		param.put("deployProvince", CommonUtils.valueOf(request.getParameter("deployProvince")));
		param.put("deployCity", CommonUtils.valueOf(request.getParameter("deployCity")));
		param.put("deployAddr", CommonUtils.valueOf(request.getParameter("deployAddr")));
		param.put("deployCode", CommonUtils.valueOf(request.getParameter("deployCode")));
		param.put("deployHouseName", CommonUtils.valueOf(request.getParameter("deployHouseName")));
		param.put("registerProvince", CommonUtils.valueOf(request.getParameter("registerProvince")));
		param.put("registerCity", CommonUtils.valueOf(request.getParameter("registerCity")));
		return param;
	}
	
	@RequestMapping(value = "addOrUpdate", method = RequestMethod.POST)
	@ResponseBody
	public String addOrUpdate(ApplicationCdn entity, HttpServletRequest request){
		JSONObject json = new JSONObject();
		try{
			IMap param = setParamCdn(request);
//			param.put("saveType", null); // 不是表字段，设置为空
			
			Long singleTaskId = entity.getSingleTaskId();
			String eType = CommonUtils.valueOf(request.getParameter("eType")); // 评测审核类型
			Map<String, Object> paramMap = objectToMap(entity);
			if(singleTaskId != null){
				long count = applicationCdnService.getBySingleTaskId(singleTaskId.toString());
				if(count > 0){
					applicationCdnService.update(param);
					updateByEvalType(entity, Integer.valueOf(eType), 2);
				} else {
					applicationCdnService.add(paramMap);
					updateByEvalType(entity, Integer.valueOf(eType), 1);
				}
			} else {
				applicationCdnService.add(paramMap);
				updateByEvalType(entity, Integer.valueOf(eType), 1);
			}
			
			// 更新工单状态
			String saveType = entity.getSaveType();
			String statue = CommonUtils.valueOf(request.getParameter("statue"));
			if(StringUtils.isNotBlank(saveType) && Integer.valueOf(saveType) == ApplicationCdn.EVAL_APPLICATION_SAVE){ // 保存
				IMap singleTaskMap = new IMap();
				if(Integer.valueOf(statue) == SingleTask.EVAL_SINGLETASK_STATUE_RETURN || Integer.valueOf(statue) == SingleTask.EVAL_SINGLETASK_STATUE_RETURNUPDATE){
					singleTaskMap.put("statue", statue);
				} else {
					singleTaskMap.put("statue", SingleTask.EVAL_SINGLETASK_STATUE_NOTSUB);
				}
				singleTaskMap.put("id", singleTaskId);
				singleTaskService.update(singleTaskMap);
				
				// 增加流程记录
//				Map<String, Object> flowMap = new HashMap<>();
//				flowMap.put("singleTaskId", singleTaskId);
//				Map<String,Object> userMap = singleTaskService.getUserById(singleTaskId);
//				flowMap.put("userName", userMap == null?"张三":userMap.get("UserName").toString());
//				flowMap.put("handleTime", new Date());
//				flowMap.put("statue", SingleTask.EVAL_SINGLETASK_STATUE_NOTSUB);
//				flowMap.put("reason", "");
//				
//				taskFlowService.add(flowMap);
			} else if(StringUtils.isNotBlank(saveType) && Integer.valueOf(saveType) == ApplicationCdn.EVAL_APPLICATION_TEMPORARY_SAVE){ // 暂保存
				
			}
			json.put("flag", true);
		}catch(Exception e){
			if(log.isErrorEnabled()){
				log.error(e.getMessage(),e);
			}
			json.put("flag",false);
		}
		return json.toString();
	}
	
	/**
	 * 各类型 表单审核新增或修改
	 */
	private void updateByEvalType(ApplicationCdn entity, int type, int addOrUpdateFlag){
		Long singleTaskId = entity.getSingleTaskId();
		if(addOrUpdateFlag == 1){ // 新增
//			long s = applicationCdnService.getMaxId();
			if(type == SingleTask.EVAL_SINGLETASK_TYPE_NOTINTER){  // idc业务评测(不含互联网资源协作)
				addBackInstallList(entity.getBackInstallList(), singleTaskId.toString());
				addGameInstallList(entity.getGameInstallList(), singleTaskId.toString());
				addCoverList(entity.getCoverList(), singleTaskId.toString());
			} else if(type == SingleTask.EVAL_SINGLETASK_TYPE_ONLYINTER){ // idc业务评测(仅限互联网资源协作)
				// 新增 机房 信息
				addNodeList(entity.getNodeList(), singleTaskId.toString());
				addCoverList(entity.getCoverList(), singleTaskId.toString());
			} else if(type == SingleTask.EVAL_SINGLETASK_TYPE_ISP){ // ISP业务评测 
				addBackInstallList(entity.getBackInstallList(), singleTaskId.toString());
				addGameInstallList(entity.getGameInstallList(), singleTaskId.toString());
				addCoverList(entity.getCoverList(), singleTaskId.toString());
			} else if(type == SingleTask.EVAL_SINGLETASK_TYPE_CDN){ // CDN业务评测
				// 新增 node 信息
				addNodeList(entity.getNodeList(), singleTaskId.toString());
				// 新增cname 信息
				addCnameList(entity.getCnameList(), singleTaskId.toString());
				addCoverList(entity.getCoverList(), singleTaskId.toString());
			}
		} else if(addOrUpdateFlag == 2){ // 修改
			if(type == SingleTask.EVAL_SINGLETASK_TYPE_NOTINTER){  // idc业务评测(不含互联网资源协作)
				applicationCoverInfoService.delete(singleTaskId.toString());
				applicationInstallAddrGameService.delete(singleTaskId.toString());
				applicationInstallAddrBackService.delete(singleTaskId.toString());
				
				addBackInstallList(entity.getBackInstallList(), singleTaskId.toString());
				addGameInstallList(entity.getGameInstallList(), singleTaskId.toString());
				addCoverList(entity.getCoverList(), singleTaskId.toString());
			} else if(type == SingleTask.EVAL_SINGLETASK_TYPE_ONLYINTER){ // idc业务评测(仅限互联网资源协作)
				// 修改 机房 信息
				applicationCdnNodeService.delete(singleTaskId.toString());
				addNodeList(entity.getNodeList(), singleTaskId.toString());
				
				applicationCoverInfoService.delete(singleTaskId.toString());
				addCoverList(entity.getCoverList(), singleTaskId.toString());
			} else if(type == SingleTask.EVAL_SINGLETASK_TYPE_ISP){ // ISP业务评测 
				applicationCoverInfoService.delete(singleTaskId.toString());
				applicationInstallAddrGameService.delete(singleTaskId.toString());
				applicationInstallAddrBackService.delete(singleTaskId.toString());
				
				addBackInstallList(entity.getBackInstallList(), singleTaskId.toString());
				addGameInstallList(entity.getGameInstallList(), singleTaskId.toString());
				addCoverList(entity.getCoverList(), singleTaskId.toString());
			} else if(type == SingleTask.EVAL_SINGLETASK_TYPE_CDN){ // CDN业务评测
				// 修改 node 信息
				applicationCdnNodeService.delete(singleTaskId.toString());
				addNodeList(entity.getNodeList(), singleTaskId.toString());
				applicationCoverInfoService.delete(singleTaskId.toString());
				
				// 修改 cname 信息
				applicationCdnCNameService.delete(singleTaskId.toString());
				addCnameList(entity.getCnameList(), singleTaskId.toString());
				addCoverList(entity.getCoverList(), singleTaskId.toString());
			}
		}
	}
	
	public Map<String, Object> objectToMap(ApplicationCdn entity){
		Map<String, Object> paramMap = new HashMap<>();
		paramMap.put("singleTaskId", entity.getSingleTaskId());
		paramMap.put("number", entity.getNumber());
		paramMap.put("applicationDate", entity.getApplicationDate());
		paramMap.put("name", entity.getName());
		paramMap.put("address", entity.getAddress());
		paramMap.put("code", entity.getCode());
		paramMap.put("contacts", entity.getContacts());
		paramMap.put("tel", entity.getTel());
		paramMap.put("moveTle", entity.getMoveTle());
		paramMap.put("fax", entity.getFax());
		paramMap.put("eMail", entity.geteMail());
		paramMap.put("type", entity.getType());
		paramMap.put("gbps", entity.getGbps());
		paramMap.put("linkNum", entity.getLinkNum());
		paramMap.put("systemName", entity.getSystemName());
		paramMap.put("productionUnit", entity.getProductionUnit());
		paramMap.put("version", entity.getVersion());
		paramMap.put("handleInfo", entity.getHandleInfo());
		paramMap.put("remark", entity.getRemark());
		paramMap.put("duties", entity.getDuties());
		paramMap.put("pushTime", entity.getPushTime());
		
		paramMap.put("houseNum", entity.getHouseNum());
		paramMap.put("houseName", entity.getHouseName());
		paramMap.put("isShare", entity.getIsShare());
		paramMap.put("gameProvince", entity.getGameProvince());
		paramMap.put("gameCity", entity.getGameCity());
		paramMap.put("houseAddress", entity.getHouseAddress());
		paramMap.put("postalCode", entity.getPostalCode());
		paramMap.put("idcType", entity.getIdcType());
		paramMap.put("unitFullName", entity.getUnitFullName());
		paramMap.put("contractName", entity.getContractName());
		paramMap.put("signTime", entity.getSignTime());
		paramMap.put("contractEffBeginTime", entity.getContractEffBeginTime());
		paramMap.put("contractEffEndTime", entity.getContractEffEndTime());
		paramMap.put("moduleType1", entity.getModuleType1());
		paramMap.put("moduleContent1", entity.getModuleContent1());
		paramMap.put("moduleType2", entity.getModuleType2());
		paramMap.put("moduleContent2", entity.getModuleContent2());
		paramMap.put("houseNodeName", entity.getHouseNodeName());
		paramMap.put("nodeNum", entity.getNodeNum());
		paramMap.put("evalType", entity.getEvalType());
		paramMap.put("lastEvalTime", entity.getLastEvalTime());
		paramMap.put("lastNum", entity.getLastNum());
		paramMap.put("lastMechanism", entity.getLastMechanism());
		paramMap.put("deployInfo", entity.getDeployInfo());
		paramMap.put("deployIsShare", entity.getDeployIsShare());
		paramMap.put("deployProvince", entity.getDeployProvince());
		paramMap.put("deployCity", entity.getDeployCity());
		paramMap.put("deployAddr", entity.getDeployAddr());
		paramMap.put("deployCode", entity.getDeployCode());
		paramMap.put("deployHouseName", entity.getDeployHouseName());
		paramMap.put("registerProvince",entity.getRegisterProvince());
		paramMap.put("registerCity",entity.getRegisterCity());
		
		return paramMap;
	}
	
	/**
	 * 企业侧提交
	 * @param singleTaskId
	 * @param statue
	 * @return
	 */
	@RequestMapping(value = "submitCdn", method = RequestMethod.POST)
	@ResponseBody
	public String submitCdn(String singleTaskId, String statue,HttpServletRequest request){
		JSONObject json = new JSONObject();
		try{
			IMap paramMap = new IMap();
			Map<String, Object> singleTask = singleTaskService.getById(singleTaskId);
			if(singleTask != null){
				paramMap.put("singleTaskId", singleTaskId);
				paramMap.put("formName", CommonUtils.valueOf(singleTask.get("name")));
				paramMap.put("business", CommonUtils.valueOf(singleTask.get("applyBusiness")));
				if(Integer.valueOf(statue).intValue() == SingleTask.EVAL_SINGLETASK_STATUE_JUDGING){ // 评测中
					paramMap.put("statue", TaskAudit.EVAL_TASTAUDIT_STATUE_HANLE);
				} else if(Integer.valueOf(statue).intValue() == SingleTask.EVAL_SINGLETASK_STATUE_YESPATCH){ //已补正
					paramMap.put("statue", TaskAudit.EVAL_TASTAUDIT_STATUE_YESPATCH);
				} else {
					paramMap.put("statue", TaskAudit.EVAL_TASTAUDIT_STATUE_NOTAUDIT);
					paramMap.put("returnNum", 0);
					paramMap.put("timeLength", 0);
					paramMap.put("createTime", new Date());
					paramMap.put("updateTime", new Date());
					paramMap.put("businessType", CommonUtils.valueOf(singleTask.get("type")));
				}
				paramMap.put("lastSubmitTime", new Date());
			}
			
			Map<String, Object> applicationCdn = applicationCdnService.getInfoBySingleTaskId(singleTaskId);
			if(applicationCdn != null){
				paramMap.put("companyName", CommonUtils.valueOf(applicationCdn.get("name")));
				paramMap.put("formNum", CommonUtils.valueOf(applicationCdn.get("number")));
			}
			if(taskAuditService.getCountBySingleTaskId(singleTaskId) > 0){
				taskAuditService.update(paramMap);
			} else {
				taskAuditService.add(paramMap);
			}
			
			// 更新工单状态
			IMap singleTaskMap = new IMap();
			singleTaskMap.put("statue", statue);
			singleTaskMap.put("id", singleTaskId);
			singleTaskMap.put("lastSubmitTime", new Date());
			singleTaskService.update(singleTaskMap);
			
			// 增加流程记录
			Map<String, Object> flowMap = new HashMap<>();
			flowMap.put("singleTaskId", singleTaskId);
			Map<String,Object> userMap = singleTaskService.getUserById(singleTaskId);
			flowMap.put("userName", userMap == null?"张三":userMap.get("UserName").toString());
			flowMap.put("handleTime", new Date());
			String btnName = CommonUtils.valueOf(request.getParameter("btnName"));
//			flowMap.put("statue", SingleTask.EVAL_SINGLETASK_STATUE_YESSUB);
			flowMap.put("statue", btnName);
			flowMap.put("reason", "");
			
			taskFlowService.add(flowMap);
			json.put("flag", true);
			
			//重新提测,修改历史工单表单状态
			if(StringUtils.equals(btnName,"重新提测")) {
				String formNumber = CommonUtils.valueOf(applicationCdn.get("number"));
				Map<String,Object> params = new HashMap<String,Object>();
				params.put("form_statue", 0);
				String queryConf = " where form_number='"+formNumber+"'";
				taskFlowService.updateHistoryWorkOrder(params, queryConf);
			}
		}catch(Exception e){
			if(log.isErrorEnabled()){
				log.error(e.getMessage(),e);
			}
			json.put("flag",false);
		}
		return json.toString();
	}
	
	@RequestMapping(value = "updateStatue", method = RequestMethod.POST)
	@ResponseBody
	public String updateStatue(HttpServletRequest request){
		JSONObject json = new JSONObject();
		try{
			String statue = CommonUtils.valueOf(request.getParameter("statue"));
			String singleTaskId = CommonUtils.valueOf(request.getParameter("singleTaskId"));
			
			// 更新工单状态 和 研究院审核状态
			IMap imap = new IMap();
			imap.put("statue", statue);
			imap.put("singleTaskId", singleTaskId);
			imap.put("updateTime", new Date());
			taskAuditService.update(imap);
			
			imap.put("singleTaskId", null); // 不是库里边字段,去掉
			imap.put("updateTime", null); // 不是库里边字段,去掉
			imap.put("id", singleTaskId);
			if(Integer.valueOf(statue) == TaskAudit.EVAL_TASTAUDIT_STATUE_AUDIT){ // 核实
				imap.put("statue", SingleTask.EVAL_SINGLETASK_STATUE_VERIFY);
			} else if(Integer.valueOf(statue) == TaskAudit.EVAL_TASTAUDIT_STATUE_BACK){ //退回修改 
				imap.put("statue", SingleTask.EVAL_SINGLETASK_STATUE_RETURNUPDATE);
			} else if(Integer.valueOf(statue) == TaskAudit.EVAL_TASTAUDIT_STATUE_HANLE){ // 评测中
				imap.put("statue", SingleTask.EVAL_SINGLETASK_STATUE_JUDGING);
			} else if(Integer.valueOf(statue) == TaskAudit.EVAL_TASTAUDIT_STATUE_NOTAUDIT){ // 撤销核实
				imap.put("statue", SingleTask.EVAL_SINGLETASK_STATUE_RETURNUPDATE);
			}
			singleTaskService.update(imap);
			
			// 增加流程记录
			Map<String, Object> flowMap = new HashMap<>();
			flowMap.put("singleTaskId", singleTaskId);
			Map<String,Object> userMap = singleTaskService.getUserById(singleTaskId);
			flowMap.put("userName", userMap == null?"张三":userMap.get("UserName").toString());
			flowMap.put("handleTime", new Date());
			String btnName = CommonUtils.valueOf(request.getParameter("btnName"));
			flowMap.put("statue", btnName);
			
			String reason = CommonUtils.valueOf(request.getParameter("reason"));
			if(StringUtils.isNotBlank(reason)){
				flowMap.put("reason", reason);
			} else {
				flowMap.put("reason", "");
			}
			taskFlowService.add(flowMap);
			json.put("flag", true);
		}catch(Exception e){
			if(log.isErrorEnabled()){
				log.error(e.getMessage(),e);
			}
			json.put("flag",false);
		}
		return json.toString();
	}
	
	@RequestMapping(value = "downloadtemplate")
	@ResponseBody
	 public void downloadtemplate(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
		try{
			request.setCharacterEncoding("UTF-8");
		    String name = request.getParameter("name");//获取要下载的文件名
		    
		    String childPath = "";
		    String filename = "";
		    if(StringUtils.isNotBlank(name)){
		    	List<Map<String,Object>> list = dictionaryService.getByType(name);
		    	if(null != list && !list.isEmpty()){
		    		childPath = list.get(0).get("codeKey").toString();
		    		filename = list.get(0).get("codeValue").toString();
		    		
		    		downLoad(request, resp, filename, request.getSession().getServletContext().getRealPath("/") + childPath);
		    	}
		    }
		}catch(Exception e){
			e.getMessage();
		} 
	  }

	/**
	 * 评测附件下载
	 * @param request
	 * @param resp
	 */
	@RequestMapping(value = "fileDownLoad")
	@ResponseBody
	public void fileDownLoad(HttpServletRequest request, HttpServletResponse resp){
		String fileId = request.getParameter("fileId");
		try {
			if(StringUtils.isNotBlank(fileId)){
				Map<String, Object> map = applicationFileService.getById(fileId);
				if(null != map){
					String rootPath = dictionaryService.getValueByTypeAndKey(ROOTPATH, "0");
					if(StringUtils.isBlank(rootPath)){
						log.error("请检查字典表EVAL_UPLOADFILE_ROOTPATH配置");
					} else {
						String path = rootPath + map.get("path").toString();
						downLoad(request, resp, map.get("name").toString(), path);
					}
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private void downLoad(HttpServletRequest request, HttpServletResponse resp, String filename, String childPath) throws IOException{
		request.setCharacterEncoding("UTF-8");
		//第一步：设置响应类型
	    resp.setContentType("application/force-download");//应用程序强制下载
	    //第二读取文件
	    String path = childPath;
	    if ("/".equals(File.separator))
	    	path = path.replace("\\", "/");
	    
	    InputStream in = new FileInputStream(path);
	    //设置响应头，对文件进行url编码
	    filename = URLEncoder.encode(filename, "UTF-8");
	    resp.setHeader("Content-Disposition", "attachment;filename="+filename);   
	    resp.setContentLength(in.available());
	    
	    OutputStream out = resp.getOutputStream();
	    byte[] b = new byte[1024];
	    int len = 0;
	    while((len = in.read(b))!=-1){
	      out.write(b, 0, len);
	    }
	    out.flush();
	    out.close();
	    in.close();
	}
	
	@RequestMapping(value = "fileUpload", method = RequestMethod.POST)
	@ResponseBody
	public String fileUpload(@RequestParam(value = "upFiles", required = false) MultipartFile[] upFiles, HttpServletRequest request){
		JSONObject json = new JSONObject();
		try{
			// 附件上传
			if(upFiles != null && upFiles.length > 0){
				String singleTaskId = CommonUtils.valueOf(request.getParameter("singleTaskId"));
				String type = CommonUtils.valueOf(request.getParameter("type"));
				boolean hadExise = applicationFileService.getCountBySingleTaskId(singleTaskId, type) > 0;
				
				if(hadExise) {
					applicationFileService.delete(singleTaskId, type);
				}
				
				for(MultipartFile upFile : upFiles){
					if(upFile != null) uploadFile(upFile, request, hadExise);
				}
			}
			json.put("flag", true);
		}catch(Exception e){
			if(log.isErrorEnabled()){
				log.error(e.getMessage(),e);
			}
			json.put("flag",false);
		}
		return json.toString();
	}
	
	/**
	 * 附件上传
	 * @param uploadFile
	 * @param request
	 * @return
	 */
	public void uploadFile(MultipartFile upFile, HttpServletRequest request, boolean hadExise) {
		String myFileName = "";
		if(!upFile.isEmpty()){
			myFileName = upFile.getOriginalFilename();
			
			boolean hasParamInfo = true;
			String rootPath = dictionaryService.getValueByTypeAndKey(ROOTPATH, "0");
			if(StringUtils.isBlank(rootPath)){
				hasParamInfo = false;
				log.error("请检查字典表EVAL_UPLOADFILE_ROOTPATH配置");
			}
			String childPath = dictionaryService.getValueByTypeAndKey(CHILDPATH, "0");
			if(StringUtils.isBlank(childPath)){
				hasParamInfo = false;
				log.error("请检查字典表EVAL_UPLOADFILE_CHILDPATH配置");
			}
			
			if(hasParamInfo){
				String fileName = "";
				try {
					if (childPath != null && !childPath.isEmpty() ) {
						fileName = CommonUtil.uploadFile(myFileName, upFile.getInputStream(), rootPath, childPath);
					} else {
						
					}
					String singleTaskId = CommonUtils.valueOf(request.getParameter("singleTaskId"));
					String type = CommonUtils.valueOf(request.getParameter("type"));
					Map<String, Object> map = Maps.newHashMap();
					map.put("name", myFileName);
					map.put("path", childPath+"/"+fileName);
					map.put("type", type);
					map.put("singleTaskId", CommonUtils.valueOf(request.getParameter("singleTaskId")));
					
					applicationFileService.add(map);
					
					/*if(hadExise){ // 修改
						applicationFileService.delete(singleTaskId, type);
						applicationFileService.add(map);
					} else { // 新增
						applicationFileService.add(map);
					}*/
				} catch (IOException ioe) {
					ioe.printStackTrace();
				} catch (Exception e) {
					if(log.isErrorEnabled()){
						log.error(e.getMessage(),e);
					}
				}
			}
		}
	}
	
	/**
	 * 获取评测不通过信息
	 * @param singleTaskId
	 * @return
	 */
	@RequestMapping(value = "getNotAdoptInfo", method = RequestMethod.POST)
	@ResponseBody
	public String getNotAdoptInfo(HttpServletRequest request){
		JSONObject json = new JSONObject();
		String singleTaskId = CommonUtils.valueOf(request.getParameter("singleTaskId"));
		try{
			if(StringUtils.isNotBlank(singleTaskId)){
				Map<String,Object> param = new HashMap<String,Object>();
				param.put("singleTaskId", singleTaskId); //评测任务id
				Map<String,Object> data = applicationCdnService.getEntity(param);
				
				// 获取评测通过信息，责任人和联系方式，及处理时间
				String deptPerson = dictionaryService.getValueByTypeAndKey(EVAL_REPORT_USER, "0");
				if(StringUtils.isBlank(deptPerson)){
					log.error("请检查字典表EVAL_REPORT_USER配置");
				} else {
					data.put("deptPerson", deptPerson);
				}
				String personTel = dictionaryService.getValueByTypeAndKey(EVAL_REPORT_CONTACT, "0");
				if(StringUtils.isBlank(deptPerson)){
					log.error("请检查字典表EVAL_REPORT_CONTACT配置");
				} else {
					data.put("personTel", personTel);
				}
				Map<String, Object> taskAuditMap = taskAuditService.getBySingleTaskId(singleTaskId);
				if(null != taskAuditMap && StringUtils.isNotBlank(taskAuditMap.get("updateTime").toString())){
					Date handleTime = (Date)taskAuditMap.get("updateTime");
					Calendar cal = Calendar.getInstance(); 
					cal.setTime(handleTime);
					data.put("handleDay", cal.get(Calendar.DAY_OF_MONTH));
					data.put("handleMonth", (cal.get(Calendar.MONTH) + 1)+"");
					data.put("handleYear", cal.get(Calendar.YEAR));
				}
				
				// 获取评测不通过原因
				List<Map<String, Object>> flowList = taskFlowService.getBySingleTaskIdAndStatue(singleTaskId, "评测不通过");
				if(null != flowList && flowList.size() > 0){
					json.put("flowData", flowList);
				}
				
				json.put("data", data);
				// 获取项目评测不通过信息
				json.put("notAdoptData", evalProjectService.getBySingleTaskIdAndResult(singleTaskId, 2+""));
				json.put("flag", true);
			} else {
				log.error("获取评测不通过信息, singleTaskId 值为空");
				json.put("flag", false);
			}
		}catch(Exception e){
			if(log.isErrorEnabled()){
				log.error(e.getMessage(),e);
			}
			json.put("flag",false);
		}
		return json.toString();
	}
}
